package com.riaevolution.components
{
	import mx.controls.TextInput;
	import mx.controls.LinkButton;
	import flash.display.DisplayObject;
	import flash.events.Event;
	import mx.events.FlexEvent;

	public class TextInputRemovable extends TextInput
	{
		public static var iconRemove:Class;
		private var removeIcon:LinkButton;
		public function TextInputRemovable()
		{
			//TODO: implement function
			super();
			addEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);
		}
		private function creationCompleteHandler(event:FlexEvent):void {
           	var icon:LinkButton = new LinkButton();
			icon.width = 20;
			icon.height = 18;
			icon.y = height/2-9;
			icon.x = width + 5;
			icon.toolTip = "Remover";
			icon.setStyle("rollOverColor",0xFFFFFF);
			icon.setStyle("themeColor",0xFFFFFF);
			icon.setStyle("cornerRadius ",0);
			if(TextInputRemovable.iconRemove != null) {
				icon.setStyle("icon",TextInputRemovable.iconRemove);
			}
			icon.addEventListener("click",removeMe);
			removeIcon = icon;
			addChild(icon);
			width = icon.x + icon.width;
        }
		private function removeMe(event:*):void{
			dispatchEvent(new Event("onRemove"));
		}
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
			super.updateDisplayList(unscaledWidth,unscaledHeight);
		}
	}
}